-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[TargetInstrInfo] Add target hook for InstrSchedModel latency. [NFCI] #128925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kerbowa
wants to merge
1
commit into
main
Choose a base branch
from
users/kerbowa/sched-dynamic-latencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/TargetInstrInfo.h llvm/include/llvm/CodeGen/TargetSchedule.h llvm/lib/CodeGen/TargetInstrInfo.cpp llvm/lib/CodeGen/TargetSchedule.cpp
View the diff from clang-format here.diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index 70c9d86e2..874f28af3 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -1842,11 +1842,9 @@ TargetInstrInfo::getInstrLatency(const TargetSchedModel &TargetSchedModel,
return std::nullopt;
}
-std::optional<unsigned> TargetInstrInfo::getOperandLatency(const TargetSchedModel &SchedModel,
- const MachineInstr *DefMI,
- unsigned DefOperIdx,
- const MachineInstr *UseMI,
- unsigned UseOperIdx) const {
+std::optional<unsigned> TargetInstrInfo::getOperandLatency(
+ const TargetSchedModel &SchedModel, const MachineInstr *DefMI,
+ unsigned DefOperIdx, const MachineInstr *UseMI, unsigned UseOperIdx) const {
// Only handle the TargetSchedModel-based computation here. If no
// instruction scheduling model is available, defer to the caller.
if (!SchedModel.hasInstrSchedModel())
@@ -1866,9 +1864,11 @@ std::optional<unsigned> TargetInstrInfo::getOperandLatency(const TargetSchedMode
if (DefIdx < SCDesc->NumWriteLatencyEntries) {
// Lookup the definition's write latency in SubtargetInfo.
const TargetSubtargetInfo *STI = SchedModel.getSubtargetInfo();
- const MCWriteLatencyEntry *WLEntry = STI->getWriteLatencyEntry(SCDesc, DefIdx);
+ const MCWriteLatencyEntry *WLEntry =
+ STI->getWriteLatencyEntry(SCDesc, DefIdx);
unsigned WriteID = WLEntry->WriteResourceID;
- unsigned Latency = WLEntry->Cycles >= 0 ? static_cast<unsigned>(WLEntry->Cycles) : 1000u;
+ unsigned Latency =
+ WLEntry->Cycles >= 0 ? static_cast<unsigned>(WLEntry->Cycles) : 1000u;
if (!UseMI)
return Latency;
@@ -1884,7 +1884,8 @@ std::optional<unsigned> TargetInstrInfo::getOperandLatency(const TargetSchedMode
++UseIdx;
}
int Advance = STI->getReadAdvanceCycles(UseDesc, UseIdx, WriteID);
- if (Advance > 0 && static_cast<unsigned>(Advance) > Latency) // unsigned wrap
+ if (Advance > 0 &&
+ static_cast<unsigned>(Advance) > Latency) // unsigned wrap
return 0;
return Latency - Advance;
}
@@ -1896,8 +1897,7 @@ std::optional<unsigned> TargetInstrInfo::getOperandLatency(const TargetSchedMode
!DefMI->getDesc().operands()[DefOperIdx].isOptionalDef() &&
SchedModel.getMCSchedModel()->isComplete()) {
errs() << "DefIdx " << DefIdx << " exceeds machine model writes for "
- << *DefMI
- << " (Try with MCSchedModel.CompleteModel set to false)";
+ << *DefMI << " (Try with MCSchedModel.CompleteModel set to false)";
llvm_unreachable("incomplete machine model");
}
#endif
|
fe6782d to
4058cec
Compare
These hooks already exist when using instruction itineraries for latency info, this patch adds them for the newer TargetSchedModel. Allows targets to dynamically set latency values in the DAG builder. This is useful in multi-pass schedulers like in the AMDGUP backend where we may want to schedule a region multiple times with a different machine model or tweaked latencies for a specific instruction type.
4058cec to
450737f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

These hooks already exist when using instruction itineraries for latency
info, this patch adds them for the newer TargetSchedModel.
Allows targets to dynamically set latency values in the DAG builder.
This is useful in multi-pass schedulers like in the AMDGUP backend where
we may want to schedule a region multiple times with a different machine
model or tweaked latencies for a specific instruction type.